<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="sitemesh" uri="http://www.opensymphony.com/sitemesh/decorator" %>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<div id="dialog-message" title="信息">
   <p id="dialogMessage"></p>
</div>
<div class="header">
    <div class="header_block">
        <div class="header_logo">
            <h2>昆山市企业投融资企业服务平台（商业版）</h2>
        </div>
        <div id="header_menu">
                <jsp:include page="/WEB-INF/layouts/menu.jsp"/>
        </div>
        <div class="header_banner">
            <%--<img class="bank_logo" src="${ctx}/static/project/images/smbc.png" alt="">--%>
            <h1>昆山市企业投融资企业服务平台</h1>
            <div class="opera_out">
                <div class="opera">
                    <div id="willExpiremessage" class="top_tip"></div>
                    <div class="top_tip" style="display: none;"><img src="${ctx}/static/project/images/clock.png"/><span id="licenseMsg"></span></div>
                    <shiro:user>
                        用户: <shiro:principal property="fullName"/> &nbsp; &nbsp;
                        机构: <shiro:principal property="field03"/> &nbsp; &nbsp;
                        机构代码: <shiro:principal property="field02"/>&nbsp;
                    </shiro:user>
                    <a href="javascript:void(0)" onclick="menuLink('${ctx}/system/systemPassword/toEditPassword',this)">密码修改</a> &nbsp; &nbsp;
                    <shiro:user>
                        <a href="${ctx}/logout" name="logout">登出</a>
                    </shiro:user>
                </div>
            </div>
        </div>


    </div>


</div>

<div id="dialog-change-password" title="密码修改" style="display: none;">
	<p class="validate_tips"></p>

	<form id="passwordForm">
        <input type="hidden" name="m_curUserId" id="m_curUserId"/>
        <table class="searchtable">
            <tbody>
            <tr>
                <td class="bg_gray">旧密码</td>
                <td>
                    <input type="password" name="m_oldpassowrd" id="m_oldpassowrd" maxlength="100" class="text_medium"/>
                </td>
            </tr>

            <tr>
                <td class="bg_gray">新密码</td>
                <td>
                    <input type="password" name="m_newpassowrd" id="m_newpassowrd" maxlength="100" class="text_medium"/>
                </td>
            </tr>

            <tr>
                <td class="bg_gray">新密码确认</td>
                <td>
                    <input type="password" name="m_newpassowrd2" id="m_newpassowrd2" maxlength="100" class="text_medium"/>
                </td>

            </tr>

            </tbody>
        </table>
	</form>
</div>

<script type="text/javascript">
    function openDialog4PC(){
        $( "#dialog-change-password" ).dialog( "open" );
        $( ".validateTips" ).text("");
    }

    $(function(){
        var m_curUserId = $( "#m_curUserId" ),
            m_oldpassowrd = $( "#m_oldpassowrd" ),
            m_newpassowrd = $( "#m_newpassowrd" ),
            m_newpassowrd2 = $( "#m_newpassowrd2" ),
           allFields = $( [] ).add( m_oldpassowrd ).add( m_newpassowrd ).add( m_newpassowrd2 );

        $( "#dialog-message" ).dialog({
            autoOpen: false,
            width: 400,
            show: {
                effect: "blind",
                duration: 1000
            },
            hide: {
                effect: "explode",
                duration: 1000
            },
            modal: true,
            buttons: {
                "关闭": function () {
                    $(this).dialog("close");
                }
            }
        });

        $( "#dialog-change-password" ).dialog({
            autoOpen: false,
            height: 260,
            width: 450,
            modal: true,
            buttons: {
                "保存": function() {
                    var bValid = true;
                    allFields.removeClass( "ui-state-error" );

                    bValid = bValid && checkRequired( m_oldpassowrd, "旧密码");
                    bValid = bValid && checkRequired( m_newpassowrd, "新密码") && checkLength( m_newpassowrd, "银行代码", 0, 10 );
                    bValid = bValid && checkRequired( m_newpassowrd2, "新密码确认") && checkLength( m_newpassowrd2, "银行名称", 0, 10 );
                    
                    var indata = {"m_curUserId":m_curUserId.val(),"m_oldpassowrd":m_oldpassowrd.val(),"m_newpassowrd":m_newpassowrd.val(),"m_newpassowrd2":m_newpassowrd2.val()};
                    //todo 验证密码规则，新密码和确认一致
                    if ( bValid ) {
                        $.post("${ctx}/public/savePassword" //todo:action还没有
                            ,$('#passwordForm').serialize()
                            ,function(a){
							var c = eval("("+a+")");
                            if(c.savePasswordFlag=="0"){ //todo  失败（旧密码不匹配）
                            	updateTips(c.msg);
                            	return false;
                            }else{   //todo 成功 后就关闭窗口
                                $( "#dialog-change-password" ).dialog( "close" );
                            }
                        });

                    }
                },
                "取消": function() {
                    $( this ).dialog( "close" );
                }
            },
            close: function() {
                allFields.val( "" ).removeClass( "ui-state-error" );
            }
        });

        $.ajax({
            url: "${ctx}/system/isPasswordWillExpire?d="+new Date().getTime(),
            success: function (response) {
                var data = $.parseJSON(response);
                if(data.result == 'true') {
                    $("#willExpiremessage").show();
                    $( "#willExpiremessage" ).text(data.tip);
                    return false;
                }else{
                    $("#willExpiremessage").hide();
                }
            }
        });

        //license
        $.ajax({
            url: "${ctx}/license/check",
            data: {"random": new Date().getTime()},
            success: function (data) {
                if(data == 'Y') {
                    $( ".top_tip" ).show();
                	$( "#licenseMsg" ).text( "服务期限已超期,请续费!" ).addClass( "ui-state-highlight" );
                    return false;
                } else {
                	$( "#licenseMsg" ).text( "" ).removeClass( "ui-state-highlight");
                	$( ".top_tip" ).hide();
                }
            }
        });

    })
</script>
